package com.playball.lottery.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.playball.lottery.R;
import com.playball.lottery.bean.KaiJiangBean;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**开奖适配器
 * Created by Administrator on 2017/2/15.
 */

public class KaiJiangAdapter extends BaseAdapter{
    public Context context;
    private LayoutInflater inflater;
    public ArrayList<KaiJiangBean> list;
    public TextView tv_shu1,tv_shu2,tv_shu3,tv_shu4,tv_shu5,tv_shu6,tv_shu7,tv_shu8;

    public KaiJiangAdapter(Context context,ArrayList<KaiJiangBean>  list){
        this.context=context;
        this.list=list;
        inflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i,View convertView, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.kaijiang_list, viewGroup, false);
            viewHolder.tv_num=(TextView) convertView.findViewById(R.id.tv_num);
            viewHolder.tv_num1=(TextView) convertView.findViewById(R.id.tv_num1);
            viewHolder.tv_num2=(TextView) convertView.findViewById(R.id.tv_num2);
            viewHolder.tv_num3=(TextView) convertView.findViewById(R.id.tv_num3);
            viewHolder.tv_num4=(TextView) convertView.findViewById(R.id.tv_num4);
            viewHolder.tv_num5=(TextView) convertView.findViewById(R.id.tv_num5);
            viewHolder.tv_num6=(TextView) convertView.findViewById(R.id.tv_num6);
            viewHolder.tv_num7=(TextView) convertView.findViewById(R.id.tv_num7);
            viewHolder.tv_num8=(TextView) convertView.findViewById(R.id.tv_num8);
            viewHolder.tv_Total=(TextView) convertView.findViewById(R.id.tv_Total);
            viewHolder.tv_DS=(TextView) convertView.findViewById(R.id.tv_DS);
            viewHolder.tv_DX=(TextView) convertView.findViewById(R.id.tv_DX);
            viewHolder.tv_WDX=(TextView) convertView.findViewById(R.id.tv_WDX);
            viewHolder.LH=(TextView) convertView.findViewById(R.id.LH);
            viewHolder.tv_shu1=(TextView) convertView.findViewById(R.id.tv_shu1);
            viewHolder.tv_shu2=(TextView) convertView.findViewById(R.id.tv_shu2);
            viewHolder.tv_shu3=(TextView) convertView.findViewById(R.id.tv_shu3);
            viewHolder.tv_shu4=(TextView) convertView.findViewById(R.id.tv_shu4);
            viewHolder.tv_shu5=(TextView) convertView.findViewById(R.id.tv_shu5);
            viewHolder.tv_shu6=(TextView) convertView.findViewById(R.id.tv_shu6);
            viewHolder.tv_shu7=(TextView) convertView.findViewById(R.id.tv_shu7);
            viewHolder.tv_shu8=(TextView) convertView.findViewById(R.id.tv_shu8);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        KaiJiangBean b=list.get(i);

        //zheli\"WinNumber\": \"13 11 16 09 05 08 03 12\",\r\n
        String str=b.getWinNumber().trim();
        if(!"".equals(str)){
            String[] content = str.split(" ");
            String[] values = new String[content.length];
            //对应文本
            String[] contents = context.getResources().getStringArray(R.array.contents);

            for (int j =0;j<content.length;j++){
                int key = Integer.valueOf(content[j]);
                values[j] = contents[key - 1];
            }


            viewHolder.tv_num1.setText(content[0]);
            viewHolder.tv_num2.setText(content[1]);
            viewHolder.tv_num3.setText(content[2]);
            viewHolder.tv_num4.setText(content[3]);
            viewHolder.tv_num5.setText(content[4]);
            viewHolder.tv_num6.setText(content[5]);
            viewHolder.tv_num7.setText(content[6]);
            viewHolder.tv_num8.setText(content[7]);
            viewHolder.tv_shu1.setText(values[0]);
            viewHolder.tv_shu2.setText(values[1]);
            viewHolder.tv_shu3.setText(values[2]);
            viewHolder.tv_shu4.setText(values[3]);
            viewHolder.tv_shu5.setText(values[4]);
            viewHolder.tv_shu6.setText(values[5]);
            viewHolder.tv_shu7.setText(values[6]);
            viewHolder.tv_shu8.setText(values[7]);


        }
        //期数
        String str_num=b.getIssue();
        viewHolder.tv_num.setText(str_num.substring(str_num.length()-2,str_num.length()));
        //总和
        viewHolder.tv_Total.setText(b.getTotal());
        viewHolder.tv_DS.setText(b.getDS());
        viewHolder.tv_DX.setText(b.getDX());
        viewHolder.tv_WDX.setText(b.getWDX());
        viewHolder.LH.setText(b.getLH());//龙虎
        return convertView;
    }

    public void setTextView(String s){
        tv_shu1.setText(s);
        tv_shu2.setText(s);
        tv_shu3.setText(s);
        tv_shu4.setText(s);
        tv_shu5.setText(s);
        tv_shu6.setText(s);
        tv_shu7.setText(s);
        tv_shu8.setText(s);
    }


    public class ViewHolder {
        TextView tv_num;
        TextView tv_num1,tv_num2,tv_num3,tv_num4,tv_num5,tv_num6,tv_num7,tv_num8;
        TextView tv_Total;
        TextView tv_DS,tv_DX,tv_WDX,LH;
        TextView tv_shu1,tv_shu2,tv_shu3,tv_shu4,tv_shu5,tv_shu6,tv_shu7,tv_shu8;
    }

}
